USE [OctoNetApps]
GO

/****** Object:  StoredProcedure [classified].[ClassifiedCategories_GetByVersion]    Script Date: 05/25/2011 07:01:38 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO






CREATE PROCEDURE [classified].[ClassifiedCategories_GetByVersion]
	@ResourceID bigint,
	@VersionCache int,
	@VersionDB int OUTPUT
AS
BEGIN

	SET NOCOUNT ON;
	
	DECLARE @MasterID bigint
	SELECT @MasterID = MasterResourceID FROM classified.ClassifiedResources WHERE ResourceID = @ResourceID
	IF (@MasterID IS NOT NULL) SET @ResourceID = @MasterID
	
	
	SELECT @VersionDB = ISNULL(CategoryTreeVersion, -1)
	FROM classified.ClassifiedResources WHERE ResourceID = @ResourceID
	
	IF (@@ROWCOUNT = 0)
		SET @VersionDB = -1
	
	IF (@VersionCache <> @VersionDB)
		BEGIN
			SELECT 
				CategoryID,
				ParentCategoryID,
				CategoryName,
				AdNameExample,
				ImageUrl,
				RedirectUrl,
				[Time],
				[ReadOnly]
			FROM classified.ClassifiedCategories
			WHERE ResourceID = @ResourceID
			ORDER BY CategoryID
		END
END





GO


